package com.pmp.controller;

import com.pmp.pojo.ProInfo;
import com.pmp.pojo.ProInfoFile;
import com.pmp.pojo.User;
import com.pmp.service.IUserService;
import com.pmp.util.MD5Util;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by think on 2017/1/2.
 */
@Controller
public class UserController {

    Logger logger = Logger.getLogger(this.getClass());

    @Resource(name = "userService")
    private IUserService userService;

    @RequestMapping(value = "/main")
    public String goMain() {
        return "/main/main";
    }
    @RequestMapping(value = "/home")
    public String goHome() {
        return "/main/home";
    }
    @RequestMapping(value = {"/index", "/"})
    public String goIndex(HttpServletRequest request, String language) {
        return "login";
    }

    @RequestMapping(value = "login")
    public String login(String username, String pwd) {
        User user = userService.login(username, MD5Util.getMD5String(pwd));
        if (user != null) {
            return "main/main";
        } else {
            return "login";
        }

    }

    @RequestMapping(value = "userindex")
    public String showUserIndex() {
        return "user/user_index";
    }

    @RequestMapping(value = "queryuser")
    @ResponseBody
    public List<User> queryUser() {
        return userService.queryUser();
    }

    @RequestMapping(value = "adduser")
    @ResponseBody
    public void addUser(User user) {
        userService.addUser(user);
    }

    @RequestMapping(value = "insertProInfo")
    @ResponseBody
    public void insertProInfo(ProInfo proInfo, ProInfoFile proInfoFile) {
        userService.insertProInfo(proInfo,proInfoFile);
    }

}
